<template>
  <div class="login-container">
    <div class="login-box">
      <div class="login-title">
        <h2>后台管理系统</h2>
        <p>Background Management System</p>
      </div>
      <el-card class="login-card">
        <el-form
          ref="loginFormRef"
          :model="loginForm"
          :rules="loginRules"
          class="login-form"
        >
          <el-form-item prop="username">
            <el-input
              v-model="loginForm.username"
              placeholder="请输入用户名"
              :prefix-icon="User"
              size="large"
            />
          </el-form-item>
          <el-form-item prop="password">
            <el-input
              v-model="loginForm.password"
              type="password"
              placeholder="请输入密码"
              :prefix-icon="Lock"
              size="large"
              @keyup.enter="handleLogin"
            />
          </el-form-item>
          <el-form-item>
            <el-button
              :loading="loading"
              type="primary"
              class="login-button"
              size="large"
              @click="handleLogin"
            >
              登录
            </el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { useRouter } from 'vue-router'
import { User, Lock } from '@element-plus/icons-vue'

const router = useRouter()
const loading = ref(false)
const loginFormRef = ref()

const loginForm = reactive({
  username: '',
  password: ''
})

const loginRules = {
  username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
  password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
}

const handleLogin = () => {
  loginFormRef.value?.validate((valid) => {
    if (valid) {
      loading.value = true
      setTimeout(() => {
        loading.value = false
        router.push('/')
      }, 1000)
    }
  })
}
</script>

<style lang="scss" scoped>
.login-container {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);

  .login-box {
    .login-title {
      text-align: center;
      margin-bottom: 40px;
      color: #fff;
      
      h2 {
        font-size: 32px;
        margin: 0 0 10px;
        text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
      }
      
      p {
        font-size: 16px;
        margin: 0;
        opacity: 0.8;
      }
    }

    .login-card {
      width: 400px;
      border-radius: 8px;
      box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
      backdrop-filter: blur(10px);
      background: rgba(255, 255, 255, 0.9);

      :deep(.el-card__body) {
        padding: 30px;
      }

      .login-form {
        .el-input {
          --el-input-hover-border: var(--el-color-primary);
          
          .el-input__wrapper {
            box-shadow: 0 0 0 1px #dcdfe6;
            
            &:hover {
              box-shadow: 0 0 0 1px var(--el-color-primary);
            }
          }
        }

        .login-button {
          width: 100%;
          letter-spacing: 4px;
          font-size: 16px;
          height: 45px;
        }
      }
    }
  }
}
</style> 